package com.example.zm_fanjiantao;

import com.example.zm_fanjiantao.config.MyWechat;
import com.example.zm_fanjiantao.config.Wechat;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class HelloController {
    @Resource
    private Wechat wechat;

    @GetMapping("/getwechat")
    public Wechat getWechat(){
        return wechat;
    };

    @Resource
    private ApplicationContext applicationContext;

    @GetMapping("/getwechat2")
    public  Wechat getWechat2(){
        Environment env = applicationContext.getEnvironment();
        String appId = env.getProperty("wechat.appId");
        String token = env.getProperty("wechat.token");
        String appSecret = env.getProperty("wechat.appSecret");
        Wechat wechat = new Wechat();
        wechat.setAppId(appId);
        wechat.setAppId(token);
        wechat.setAppSecret(appSecret);
        return  wechat;


    }

    @Resource
    private MyWechat myWechat;
    @GetMapping("/getMywechat")
    public MyWechat getMywechat(){
        return myWechat;
    }

}
